package com.jwsoft.manager.core.util;

import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.bifang.engine.cache.jetcache.utils.JetCacheUtils;
import com.bifang.module.base.common.vo.system.UserDetailVO;
import com.bifang.module.base.common.vo.system.UserVO;
import com.bifang.module.system.core.dao.service.SysUserService;
import com.jwsoft.manager.common.constant.EduCache;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 教育报名相关清除缓存工具类
 * */
@Component
public class EduEnrollClearCacheHelper {
    @Autowired
    private SysUserService sysUserService;
    /**
     * 清除所有
     * */
    public void clearAll(String idcard){
        if(StringUtils.isBlank(idcard)){
            return;
        }
        clearCacheMyEnrollPre(idcard);
        clearCacheMyEnroll(idcard);
        clearCacheMyEnrollPreFc(idcard);
        clearCacheMyEnrollPreSb(idcard);
        clearCacheMyEnrollPreJzz(idcard);
        clearCacheMyEnrollPreWq(idcard);
        clearCacheMyEnrollPreQy(idcard);
        clearCacheMyApply(idcard);
    }
    public void clearCachePreBefore(String studentEnrollPreId){
        if(StringUtils.isBlank(studentEnrollPreId)){
            return;
        }
        Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_CAN_ENROLL, CacheType.BOTH);
        if (cacheMyEnroll != null) {
            //清除我的报名缓存
            cacheMyEnroll.remove(studentEnrollPreId);
        }

    }
    /**
     * 根据身份证清除我的报名缓存缓存
     * */
    public void clearCacheMyEnroll(String idcard){
        if(StringUtils.isBlank(idcard)){
            return;
        }
        Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_MY_ENROLL, CacheType.BOTH);
        if (cacheMyEnroll != null) {
            //清除我的报名缓存
            cacheMyEnroll.remove(idcard);
        }
    }
    /**
     * 根据身份证清除我的申请缓存
     * */
    public void clearCacheMyApply(String idcard){
        if(StringUtils.isBlank(idcard)){
            return;
        }
        Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_MY_APPLY, CacheType.BOTH);
        if (cacheMyEnroll != null) {
            //清除我的申请缓存
            cacheMyEnroll.remove(idcard);
        }
    }
    /**
     * 根据登录人清除我的申请缓存
     * */
    public void clearCacheMyApplyByUserid(String userId){
        if(StringUtils.isBlank(userId)){
            return;
        }
        UserDetailVO userDetailVO=new UserDetailVO();
        userDetailVO.setUserId(userId);
        UserVO userVO=sysUserService.getUserDetail(userId);
        if(userVO!=null&&StringUtils.isNotBlank(userVO.getIdcard())){
            Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_MY_APPLY, CacheType.BOTH);
            if (cacheMyEnroll != null) {
                //清除我的申请缓存
                cacheMyEnroll.remove(userVO.getIdcard());
            }
        }

    }
    /**
     * 根据身份证清除当年适龄子女缓存
     * */
    public void clearCacheMyEnrollPre(String idcard){
        if(StringUtils.isBlank(idcard)){
            return;
        }
        Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE, CacheType.BOTH);
        if (cacheMyEnroll != null) {
            //清除我的报名缓存
            cacheMyEnroll.remove(idcard);
        }
    }
    /**
     * 根据身份证清除当年适龄子女我的房产缓存
     * */
    public void clearCacheMyEnrollPreFc(String idcard){
        if(StringUtils.isBlank(idcard)){
            return;
        }
        Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE_HOUSE, CacheType.BOTH);
        if (cacheMyEnroll != null) {
            //清除我的报名缓存
            cacheMyEnroll.remove(idcard);
        }
    }
    /**
     * 根据身份证清除当年适龄子女我的社保缓存
     * */
    public void clearCacheMyEnrollPreSb(String idcard){
        if(StringUtils.isBlank(idcard)){
            return;
        }
        Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE_SB, CacheType.BOTH);
        if (cacheMyEnroll != null) {
            //清除我的报名缓存
            cacheMyEnroll.remove(idcard);
        }
    }
    /**
     * 根据身份证清除当年适龄子女我的居住证缓存
     * */
    public void clearCacheMyEnrollPreJzz(String idcard){
        if(StringUtils.isBlank(idcard)){
            return;
        }
        Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE_JZZ, CacheType.BOTH);
        if (cacheMyEnroll != null) {
            //清除我的报名缓存
            cacheMyEnroll.remove(idcard);
        }
    }
    /**
     * 根据身份证清除当年适龄子女我的网签缓存
     * */
    public void clearCacheMyEnrollPreWq(String idcard){
        if(StringUtils.isBlank(idcard)){
            return;
        }
        Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE_WQ, CacheType.BOTH);
        if (cacheMyEnroll != null) {
            //清除我的报名缓存
            cacheMyEnroll.remove(idcard);
        }
    }
    /**
     * 根据身份证清除当年适龄子女我的企业缓存
     * */
    public void clearCacheMyEnrollPreQy(String idcard){
        if(StringUtils.isBlank(idcard)){
            return;
        }
        Cache cacheMyEnroll = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE_QY, CacheType.BOTH);
        if (cacheMyEnroll != null) {
            //清除我的报名缓存
            cacheMyEnroll.remove(idcard);
        }
    }
    /**
     * 清除表单字段信息
     * */
    public void clearCacheEnrollFormParams(String formId){
        if (StringUtils.isNotBlank(formId)) {
            Cache cache = JetCacheUtils.create(EduCache.EDU_ENROLL_FORM_PARAMS, CacheType.BOTH);
            if (cache != null) {
                cache.remove(formId);
            }
        }
    }


}
